// Copyright 2011 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


/**
 * @fileoverview Provides typedefs and structures for data used external to
 * the LayerManager.  Data can come from any level within the LayerManager.
 * Many of these definitions are also handy are used within the LayerManager
 * as well.
 *
 * Public properties:
 *   shellExtension.data.layer.ScriptType - Defines valid script units for
 *       layers.
 *   shellExtension.data.script.Type - Defines valid script types.
 *
 * Public typedefs:
 *   shellExtension.data.LayerDetails - Define objects containing layer
 *       details.
 *   shellExtension.data.LayerSettings - Define objects that contain layer
 *       settings.
 *   shellExtension.data.ScriptDetails - Define objects that contain script
 *       details.
 *
 * Public functions:
 *   shellExtension.data.createLayerDetails(id, dataStatus, ondemand, state,
 *                                          status) - Create a LayerDetails
 *       object with the given inputs.
 *   shellExtension.data.createLayerSettings(id, ondemand, state) - Create a
 *       LayerSettings object with the given inputs.
 *   shellExtension.data.createScriptDetails(id, status, type) - Create a
 *       ScriptDetails object with the given inputs.
 *
 * @author jasonstredwick@google.com (Jason Stredwick)
 */


goog.provide('shellExtension.data');
goog.provide('shellExtension.data.layer');
goog.provide('shellExtension.data.script');

goog.require('shellExtension.manifest');
goog.require('shellExtension.status');


/**
 * Valid script groups within a layer.
 * @enum {string}
 */
shellExtension.data.layer.ScriptType = {
  BACKGROUND: 'background',
  CONTENT: 'content'
};


/**
 * Valid types of scripts.
 * @enum {string}
 */
shellExtension.data.script.Type = {
  CSS: 'css',
  JS: 'javascript'
};


/**
 * A typedef for details pertaining to a layer.
 * @typedef {{id: string,
 *            dataStatus: shellExtension.status.Value,
 *            ondemand: shellExtension.manifest.layer.State,
 *            state: shellExtension.manifest.layer.State,
 *            status: shellExtension.status.Value}}
 */
shellExtension.data.LayerDetails;


/**
 * A typedef for the layer's settings.
 * @typedef {{id: string,
 *            ondemand: shellExtension.manifest.layer.State,
 *            state: shellExtension.manifest.layer.State}}
 */
shellExtension.data.LayerSettings;


/**
 * A typedef for details pertaining to a script.
 * @typedef {{id: ?string,
 *            status: shellExtension.status.Value,
 *            type: shellExtension.manifest.script.Property}}
 */
shellExtension.data.ScriptDetails;


/**
 * Constructs a layer detail object.
 * @param {string} id The id.
 * @param {shellExtension.status.Value} dataStatus The data status.
 * @param {shellExtension.manifest.layer.State} ondemand The ondemand state.
 * @param {shellExtension.manifest.layer.State} state The layer state.
 * @param {shellExtension.status.Value} status The layer status.
 * @return {!shellExtension.data.LayerDetails} The details.
 */
shellExtension.data.createLayerDetails = function(id, dataStatus, ondemand,
                                                  state, status) {
  return {'id': id, 'dataStatus': dataStatus, 'ondemand': ondemand,
          'state': state, 'status': status};
};


/**
 * Constructs a layer detail object.
 * @param {string} id The id.
 * @param {shellExtension.manifest.layer.State} ondemand The ondemand state.
 * @param {shellExtension.manifest.layer.State} state The layer state.
 * @return {!shellExtension.data.LayerSettings} The details.
 */
shellExtension.data.createLayerSettings = function(id, ondemand, state) {
  return {'id': id, 'ondemand': ondemand, 'state': state};
};


/**
 * Constructs a script detail object.
 * @param {?string} id The id.
 * @param {shellExtension.status.Value} status The status.
 * @param {shellExtension.manifest.script.Property} type The type.
 * @return {!shellExtension.data.ScriptDetails} The details.
 */
shellExtension.data.createScriptDetails = function(id, status, type) {
  return {'id': id, 'status': status, 'type': type};
};

